home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 434 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  4.4 KB

  1. Path: mail2news.demon.co.uk!sisyphus.demon.co.uk
  2. From: Dave.Sparks@sisyphus.demon.co.uk
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: PPC compilers
  5. Date: Sun, 7 Jan 96 22:52:20 +0000 (GMT)
  6. Organization: to be supplied
  7. Message-ID: <19960107.533250.14585@sisyphus.demon.co.uk>
  8. References: <john.hendrikx.40ka@grafix.xs4all.nl> <jasonb.820051107@cs.uwa.edu.au> <4c9i2l$h3i@sunsystem5.informatik.tu-muenchen.de> <4ck47h$g07@maureen.teleport.com> <19960106.4EE928.CF59@sisyphus.demon.co.uk> <4cokkg$415@maureen.teleport.com>
  9. X-NNTP-Posting-Host: sisyphus.demon.co.uk
  10. In-reply-to: sschaem@teleport.com's message of 7 Jan 1996 14:16:48 GMT
  11. X-Attribution: DaveS
  12. Content-Length: 3696
  13. X-Lines: 90
  14. X-Mail2News-Path: relay-4.mail.demon.net!post.demon.co.uk!sisyphus.demon.co.uk
  15.  
  16. >>>>> "SS" == Stephan Schaem <sschaem@teleport.com> writes:
  17.  
  18.   SS> Dave.Sparks@sisyphus.demon.co.uk wrote:
  19.   >> >>>>> "SS" == Stephan Schaem <sschaem@teleport.com> writes:
  20.  
  21.   >> SS> I cant see how people can write code without knowing what data or
  22.   >> SS> type they manipulate...
  23.  
  24.   >> Real-world programmers do it all the time.  If you ever want to
  25.  
  26.   SS>  So you do math operation without knowing that your destination need
  27.   SS> to be a float or a 2 byte int?
  28.  
  29. Yes.  This is a trivial example of polymorphism.
  30.  
  31.   >> join us, you'll have to learn to do it too.  One of many examples
  32.  
  33.   SS>  Real world = commercial? I'm deep in it, thanks
  34.  
  35. Is your employer happy that you're so out of touch with modern
  36. programming practices?
  37.  
  38.   >> is the ANSI C definition of the 'clock' function: the value returned
  39.   >> is of type 'clock_t', which is defined in a system-dependent header
  40.   >> file.  SAS/C defines 'clock_t' to be an unsigned 32-bit value, but
  41.   >> other implementations can (and do) define it to be signed or even
  42.   >> 64-bit floating-point.  Since the C arithmetic operations (add,
  43.   >> subtract, multiply, divide) are overloaded (can be used on values of
  44.   >> ...
  45.  
  46.   SS>  ANSI for good reason decided on a minimal size of all its basic
  47.   SS> type.  This to help you the program choose the right type for your
  48.   SS> need.
  49.  
  50.   SS>  The only way you dont care is if you typedef all the ANSI type.
  51.  
  52.   SS>  So you created a structure to hold clock value with ulong? now
  53.   SS> recompile this on the system using a clock size of 64bit... where did
  54.   SS> the upper 32bit goes... you know have code that is broken.
  55.  
  56. I know better than to declare a value as unsigned long when I'm
  57. going to assign a clock_t to it.  And if I did, I'd lose the
  58. fractional part of a floating-point clock_t, not the upper 32 bits.
  59.  
  60.   SS>  ex of something that wont break with a recompile:
  61.  
  62.   SS>  typedef short point2d
  63.  
  64.   SS>  struct    RECTANGLE {     point2d    x1;     point2d    y1;     point2d    x2;
  65.   SS> point2d    y2; } rectangle, *rectangle;
  66.  
  67.   SS>  then you declare you variable using rectangle, or point2d
  68.  
  69.   SS>  Then if later you find out in your design you need to use long (Or
  70.   SS> create another set of include for another platform), you can just
  71.   SS> chnage point2d... I rarely see that done... anyway
  72.  
  73. So you don't know that many fields in the UNIX header files have
  74. changed from 16 bits to 32 (for example the user-id and group-id
  75. in the directory-handling structures)?  You have led a sheltered life.
  76.  
  77.   SS>  ...
  78.  
  79.   SS>  about loop counter size... should I use ulong and forget about it,
  80.   SS> or use ushort to be sure of optimal speed on my target CPU and
  81.   SS> remember my declaration type in case I want to use it for a loop
  82.   SS> count bigger then 65535?. (this result in a sub/bcc vs dbcc encoding
  83.   SS> on 680x0... )
  84.  
  85. target CPU?  How quaint ...
  86.  
  87. And why use subq/bcc rather than dbcc, if speed is all-important?
  88. It's easy enough to decrement and check the upper word whenever
  89. the lower word has just expired, so why assume that a compiler
  90. will generate the slower code?  In any case, if you're using the
  91. loop counter to index an array, the compiler will probably have
  92. transformed the loop counter and be subtracting the size of an
  93. array element, to avoid the use of a (slow) multiply instruction in the
  94. body of the loop; it couldn't use dbcc anyway.  You don't get
  95. optimal speed by optimizing the instructions, but by optimizing
  96. the algorithm.
  97.  
  98. -- 
  99.         Dave.Sparks@sisyphus.demon.co.uk        (Staffordshire, England)
  100.  
  101.  ... details are more implementation-dependant than defined.
  102.  
  103. -- 
  104. UNIX is a registered trademark in the United States and other
  105. countries, licensed exclusively through X/Open Company Limited
  106.  
  107.  
  108.